//
//  CircleCell.m
//  悠狸
//
//  Created by dllo on 15/9/1.
//  Copyright (c) 2015年 Dung. All rights reserved.
//

#import "CircleCell.h"
#import "UIImageView+WebCache.h"
#import "CateModel.h"
#import "StrategyModel.h"
#import "URL.h"

@interface CircleCell()



@end

@implementation CircleCell

- (void)dealloc
{
    [_imageV release];
    [_title release];
    [_likes_count release];
    [_str release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self create];
    }
    return self;
}

- (void)create
{
    self.imageV = [[[UIImageView alloc] initWithFrame:CGRectMake(15*OffWidth, 15*OffHeight, 150*OffWidth, 130*OffHeight)] autorelease];
//    _imageV.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:_imageV];

    self.title = [[[UILabel alloc] initWithFrame:CGRectMake(180*OffWidth, 15*OffHeight, 185*OffWidth, 50*OffHeight)] autorelease];
//    _title.backgroundColor = [UIColor greenColor];
    _title.numberOfLines = 0;
    [self.contentView addSubview:_title];
    
    self.likes_count = [[[UILabel alloc] initWithFrame:CGRectMake(210*OffWidth, 80*OffHeight, 100*OffWidth, 50*OffHeight )] autorelease];
    _likes_count.textAlignment = NSTextAlignmentCenter;
//    _likes_count.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:_likes_count];
    
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"6" ofType:@"png"];
    
    UIImage *image = [UIImage imageNamed:path];
    
    UIImageView *imageVV =[[[UIImageView alloc] initWithFrame:CGRectMake(200*OffWidth, 90*OffHeight, 30*OffWidth, 30*OffHeight)] autorelease];
    imageVV.image = image;
    
    [self.contentView addSubview:imageVV];
    self.contentView.layer.cornerRadius = 8;
    self.contentView.clipsToBounds = YES;
}

#pragma mark---高亮
- (NSMutableAttributedString *)colorData:(NSString *)withStr{
    NSMutableAttributedString *dataStr = [[NSMutableAttributedString alloc] initWithString:withStr];
    
    for (int i = 0; i < withStr.length - self.str.length + 1; i++) {
        
        if ([[withStr substringWithRange:NSMakeRange(i, self.str.length)] isEqualToString:self.str]) {
            
            NSRange range = NSMakeRange(i, self.str.length);
            [dataStr addAttribute:NSForegroundColorAttributeName value:SETCOLOR(255, 114, 0) range:NSMakeRange(range.location,range.length)];
            
        }
        
    }
    return dataStr;
}
- (void)sendCate:(CateModel *)model
{
    [_imageV sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url ]placeholderImage:[UIImage imageNamed:@"000.jpg"]];
    _title.text = model.title;
#pragma mark---高亮
    _title.attributedText = [self colorData:model.title];
    
    _likes_count.text = [model.likes_count stringValue];
}

- (void)sendStrategyModel:(StrategyModel *)model
{
    [_imageV sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url ]placeholderImage:[UIImage imageNamed:@"000.jpg"]];
    _title.text = [NSString stringWithFormat:@"%@", model.title];
    _likes_count.text = [NSString stringWithFormat:@"%@", model.likes_count] ;
}

@end
